<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
     先请求A 再请求B 再请求C
   */
        function* getData() {
            console.log('A开始');
            yield setTimeout(() => {
                console.log('A成功');
                gen.next()
            }, 2000);

            console.log('B开始');
            yield setTimeout(() => {
                console.log('B成功');
                gen.next()
            }, 2000);
            console.log('C开始');
            yield setTimeout(() => {
                console.log('C成功');
                
            }, 2000)
        }

        const gen = getData()
        //调用
        gen.next()
    </script>
</body>

</html>